import { Tag } from 'ant-design-vue';
import { h } from 'vue';
import { formatToDateTime } from '/@/utils/dateUtil';

export const columns = [
  {
    title: '用户名',
    dataIndex: 'userName',
    width: 180,
    align: 'left',
    key: 'userName',
  },
  {
    title: '姓名',
    dataIndex: 'name',
    width: 100,
    align: 'left',
    key: 'name',
  },
  {
    title: '所属企业',
    dataIndex: 'alias',
    width: 180,
    align: 'left',
    key: 'alias',
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    width: 180,
    align: 'center',
    key: 'phone',
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 200,
    align: 'left',
    key: 'email',
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    align: 'center',
    customRender: ({ record }) => {
      const status = record.status;
      const enable = ~~status === 1;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
    key: 'status',
  },
  {
    title: '内置',
    dataIndex: 'isBuiltIn',
    width: 80,
    align: 'center',
    customRender: ({ record }) => {
      const builtIn = record.isBuiltIn;
      const text = builtIn ? '是' : '否';
      return text;
    },
    key: 'isBuiltIn',
  },
  {
    title: '创建时间',
    dataIndex: 'createdTime',
    width: 180,
    align: 'center',
    customRender: ({ text }) => {
      return text ? formatToDateTime(text) : '';
    },
    key: 'createdTime',
  },
  {
    title: '操作',
    key: 'action',
    width: 100,
    slots: { customRender: 'action' },
  },
];

export interface TenantNameSelectData {
  label?: string;
  value?: string;
}
